package com.colin.app.activity.main;

import android.support.v4.view.ViewPager;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.colin.app.app.AppActivity;
import com.colin.app.app.BasePresenterImpl;

/**
 * Created by Colin on 2017/1/15.
 */

public class MainPresenterImpl extends BasePresenterImpl implements MainContract.MainPresenter {

    private MainContract.MainView mMainView;
    private MainContract.MainModel mMainModel;

    public MainPresenterImpl(AppActivity mAppActivity, MainContract.MainView mMainView) {
        super(mAppActivity, mMainView);
        this.mMainView = mMainView;
        this.mMainModel = new MainModelImpl();
    }

    @Override
    public void setData() {
        mMainView.setTitle(mMainModel.getTitle());
        mMainView.initViewPager(mMainModel.getFragmentIDList(),mMainModel.getFragmentList(mAppActivity));
    }


    @Override
    public void select(int position, ViewPager viewPager, RadioGroup radiogroup) {
        if (position!=mMainModel.getPosition()){
            mMainModel.setPosition(position);
            mMainView.setTitle(mMainModel.getTitle());
            viewPager.setCurrentItem(position, true);
            for (int j = 0; j < radiogroup.getChildCount(); j++) {
                if (position == j) {
                    ((RadioButton) radiogroup.getChildAt(j)).setChecked(true);
                } else {
                    ((RadioButton) radiogroup.getChildAt(j)).setChecked(false);
                }

            }
        }
    }
}
